package com.homer.commons.sscpprotocol.server.impl;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;

import com.homer.commons.sscpprotocol.server.base.AbstractMessageEncoder;

public class RequestEncoder<T extends SscpRequestImpl> extends AbstractMessageEncoder<T> {
	public RequestEncoder(int version) {
		super(version);
	}

	protected void encodeMessage(IoSession session, T message, IoBuffer out) {
		out.put(message.getSync_head());
		out.put(message.getMainDeviceID());
		out.put(message.getSlaveDevideID());
		out.put(message.getKey());
		out.put(message.getCommandLength());
		byte[] contentBytes = message.getContentBytes();
		if (message.getCommandLength() > 0) {
			out.put(contentBytes);			
		}
		out.put(message.getSync_end());	
	}

	public void dispose() throws Exception {
	}
}